import UnitItemEvent from '@/event/UnitItemEvent';
import BaseUtil from '@/BaseUtil';
import ArrayUtil from '@/ArrayUtil';
import SelectUtil from '@/SelectUtil';
import ItemUtil from '@/ItemUtil';
export default class Item_雷电花芯 {
    static id = 'dthb';
    static itemId = FourCC('dthb');
    static casters: unit[] = [];
    static 释放(x: number, y: number, 来源?: unit, 目标?: unit, d?: any) {}
    constructor() {
        se.onUnitPickupItem(Item_雷电花芯.pickupItem);
        se.onUnitDropItem(Item_雷电花芯.dropItem);
        se.onUnitPawnItem(Item_雷电花芯.dropItem);
        se.onUnitSellItem(Item_雷电花芯.dropItem);
        BaseUtil.onTimer(1, Item_雷电花芯.timerEffect);
    }
    static timerEffect() {
        for (let u of Item_雷电花芯.casters) {
            if (!IsUnitAliveBJ(u)) continue;
            let e = SelectUtil.getRandomEnemyInRange(u, 600);
            if (e == null) continue;
            DestroyEffect(AddSpecialEffect('50.mdx', GetUnitX(e), GetUnitY(e)));
            DamageSystemInstance.applyLightingDamage(e, u, 350);
        }
        return true;
    }
    static pickupItem(d: UnitItemEvent) {
        let item = GetManipulatedItem();
        if (GetItemTypeId(item) != Item_雷电花芯.itemId) return;
        if (Item_雷电花芯.casters.includes(GetTriggerUnit())) return;
        Item_雷电花芯.casters.push(GetTriggerUnit());
    }
    static dropItem(d: UnitItemEvent) {
        let item = GetManipulatedItem();
        if (GetItemTypeId(item) != Item_雷电花芯.itemId) return;
        let u = GetTriggerUnit();
        BaseUtil.runLater(0.1, () => {
            if (ItemUtil.getItemCountOfTypeFromUnit(u, Item_雷电花芯.id) == 0) ArrayUtil.removeElement(Item_雷电花芯.casters, u);
        });
    }
}
